from UserInterface.UIInstruction import UIInstruction
from UserInterface.UIInstruction import ui_auto_add
from UserInterface.UIInstruction import GetInstTable

@ui_auto_add
class PrintHelp(UIInstruction):
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 'help'
        self.helpInfo:str = 'print help information'
        self.args:str = ''

    def Execute(self, *args) -> None:
        helpStr = ''
        helpStr += '========== HELP ==========\n'
        helpStr += 'Instruction Info:\n'
        instTable = GetInstTable()
        for item in instTable:
            helpStr += instTable[item].GetHelp()
            helpStr += '\n'
        self.logger.print(helpStr)

@ui_auto_add
class SysExit(UIInstruction):
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 'exit'
        self.helpInfo:str = 'exit from system'
        self.args:str = ''

    def Execute(self, *args) -> None:
        import sys
        sys.exit(0)

""" ========================================================== """
""" 这区间的指令为demo指令 """
@ui_auto_add
class ReadCfgCmd(UIInstruction):
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 'cfg'
        self.helpInfo:str = 'read config'
        self.args:str = ''

    def Execute(self, *args) -> None:
        self.logger.Info('read config, info: {}'.format(self.cfg.Read('info')))
        self.cfg.Save()

@ui_auto_add
class DemoCmd(UIInstruction):
    def __init__(self) -> None:
        super().__init__()
        self.instSymbol:str = 'demo'
        self.helpInfo:str = 'DemoCmd'
        self.args:str = ''

    def Execute(self, *args) -> None:
        self.logger.Info('this is demo')
        
""" ========================================================== """